﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;

namespace HuaProject.Web.Admin
{
    /// <summary>
    /// Handler 的摘要说明
    /// </summary>
    public class Handler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (context.Request.Form["name"] != null)
            {
                string n = context.Request.Form["name"].ToString();
                string pwd = context.Request.Form["pwd"].ToString();
                long id = new HuaProject.DAL.Users().CheckUser(n, pwd);
                if (id > 0)
                {
                    //string userdata = string.Format("{0}/{1}/{2}", m.ID, m.U_Name,utaobao.GetUidModel(m.ID).TU_Name);
                    string userdata = id.ToString();
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                    1, n, DateTime.Now, DateTime.Now.AddHours(24),
                    true, userdata);
                    string encticket = FormsAuthentication.Encrypt(ticket);
                    context.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encticket));
                    context.Response.Write("Success");
                }
                else
                {
                    context.Response.Write("用户名或密码错误！");
                }
            }
            else
            {
                context.Response.Write("非法登录！");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}